import { fromJS } from 'immutable';
import * as constants from './constants';

const defaultState = fromJS({
    login: localStorage.getItem("login"),
    id: localStorage.getItem("id")
});

export default (state = defaultState, action) => {
    switch(action.type) {
        case constants.CHANGE_LOGIN:
            return state.set('login', action.login);
        case constants.LOGOUT:
            return state.set('login', action.login);
        case constants.STORE_ID_USERNAME:
            return state.merge({
                id: action.id
            });
        default:
            return state;
    }
}